#include "UdpServer.hpp"
#include "User.hpp"

// ./server_udp localport
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        cerr << "Usage: " << argv[0] << " localport" << endl;
        Die(USAGE_ERR);
    }
    // string ip = argv[1];
    uint16_t port = stoi(argv[1]);

    ENABLE_CONSOLE_LOG();
    // 用户管理模块
    shared_ptr<UserManager> um = make_shared<UserManager>();
    // 网络模块
    unique_ptr<UdpServer> svr_ptr = make_unique<UdpServer>(port);   // 加入id（用户）到管理列表中
    // 注册服务
    svr_ptr->RigesterServer([&um](InetAddr& id){ um->AddUser(id); }, 
                            [&um](int sockfd, const string& message){ um->Router(sockfd, message); }, 
                            [&um](InetAddr& id){ um->DelUser(id); }
                           );
    svr_ptr->InitServer();
    svr_ptr->Start();
}